﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VirginiaCode
{
    internal class MySecurity
    {
        /// <summary>
        /// 明文
        /// </summary>
        public string Plain { get; set; }

        /// <summary>
        /// 密文
        /// </summary>
        public string Cypher { get; set; }

        /// <summary>
        /// 密钥
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 加密过程
        /// </summary>
        public void Encryption()
        {
            //todo
            Cypher = "";
            var keys = Key.ToCharArray();
            var plains = Plain.ToCharArray();
            for (int i = 0; i < plains.Length; i++)
            {
                int j = i % keys.Length;//密钥对应下标
                Cypher = Cypher + charEncryption(plains[i], keys[j]);
            }

        }

        /// <summary>
        /// 单个字符加密
        /// </summary>
        /// <param name="chrPlain"></param>
        /// <param name="chrKey"></param>
        /// <returns></returns>
        private char charEncryption(char chrPlain, char chrKey)
        {
            //todo
            return (char)((chrPlain - 97 + chrKey - 97) % 26 + 97);
        }
    }
}
